import { dict } from '@fast-crud/fast-crud';

import { BaseEmployeeApi } from '#/api';
import { BaseOrgApi } from '#/api/basic/user/baseOrg';
import { BasePositionApi } from '#/api/basic/user/basePosition';
import { DictEnum } from '#/enums/commonEnum';
import { $t } from '#/locales';
import {
  backendDict,
  createdTimeColumn,
  STATE_CONSTANT_DICT,
} from '#/plugins/fast-crud/common';

export function employeeCrud() {
  return {
    crudOptions: {
      container: {
        is: 'fs-layout-default',
      },
      request: { pageRequest: BaseEmployeeApi.pageRequest },
      actionbar: { buttons: { add: { show: false } } },
      rowHandle: { show: false },
      columns: {
        realName: {
          title: $t('basic.user.baseEmployee.realName'),
          type: 'text',
          search: { show: true },
        },
        positionId: {
          title: $t('basic.user.baseEmployee.positionId'),
          type: 'dict-select',
          dict: dict({
            value: 'id',
            label: 'name',
            async getData() {
              return await BasePositionApi.query({});
            },
          }),
          column: { component: { type: 'text' } },
          search: { show: true },
        },
        orgIdList: {
          title: '所属部门',
          column: { component: { type: 'text' } },
          type: 'dict-tree',
          dict: dict({
            isTree: true,
            value: 'id',
            label: 'name',
            async getData() {
              return await BaseOrgApi.tree({});
            },
          }),
        },
        positionStatus: {
          title: $t('basic.user.baseEmployee.positionStatus'),
          type: 'dict-radio',
          dict: backendDict(DictEnum.POSITION_STATUS),
          search: { show: true },
        },
        state: {
          title: $t('basic.user.baseEmployee.state'),
          type: 'dict-radio',
          dict: STATE_CONSTANT_DICT,
          search: { show: true },
        },
        ...createdTimeColumn({}),
      },
    },
  };
}
